package com.llbnk.springcoding.thread.rejectedPolicy;


import java.util.concurrent.RejectedExecutionHandler;

public enum RejectedPolicyEnum {

    ABORT_POLICY("ABORT_POLICY"),

    CALLERRUNS_POLICY("CALLERRUNS_POLICY"),

    DISCARDOLDEST_POLICY("DISCARDOLDEST_POLICY"),

    DISCARD_POLICY("DISCARD_POLICY"),
    ;

    private final String value;

    RejectedPolicyEnum(String value) {
        this.value = value;
    }

    public String getValue() {
        return value;
    }

    public RejectedExecutionHandler getRejectPolicy(String poolName) {
        RejectedExecutionHandler rejectedExecutionHandler = null;
        switch (this) {
            case ABORT_POLICY:
                rejectedExecutionHandler = new AbortPolicyBuildHandler(poolName);
                break;
            case CALLERRUNS_POLICY:
                rejectedExecutionHandler = new CallerrunsPolicyBuildHander(poolName);
                break;
            case DISCARD_POLICY:
                rejectedExecutionHandler = new DiscardPolicyBuildHandler(poolName);
                break;
            case DISCARDOLDEST_POLICY:
                rejectedExecutionHandler = new DiscardoldestPolicyBuildHandler(poolName);
                break;
            default:
                rejectedExecutionHandler = new AbortPolicyBuildHandler(poolName);
        }
        return rejectedExecutionHandler;
    }
}
